/*eslint-disable*/
import React from 'react';
import { withRouter } from 'react-router-dom';
import BaseTable from '@/components/table/index';
import '../../mysite.scss';
import Api from '@/api/index';
import { Modal } from 'antd';
const { confirm } = Modal;

class Logger extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            data: [],
            columns: [],
            tools: [],
            btns: [],
            batch: [],
            select: false,
            total: 0
        }
    }

    componentDidMount() {
        // table columns
        const columns = [
            {
                title: '序号',
                width: 80,
                key: 'index',
                render: (text, record, index) => (index + 1)
            },
            {
                title: '登录名',
                dataIndex: 'name',
                width: 150,
            },
            {
                title: '访问地址',
                dataIndex: 'ip',
            },
            {
                title: '浏览器',
                dataIndex: 'brower',
            },
            {
                title: '登录时间',
                dataIndex: 'createdAt',
            },
        ];
        //操作按钮
        const btns = [
            { name: '清空', action: this.handleClear, theme: 'danger' },
        ]

        this.setState({
            columns: columns,
            btns: btns
        })
        //获取列表
        this.getList(this.state.listQuery)
    }

    //清空
    handleClear = () => {
        confirm({
            title: '提示',
            content: '是否清空日志列表？',
            okText: 'Yes',
            okType: 'danger',
            cancelText: 'No',
            onOk() {
                console.log('OK');
            },
            onCancel() {
                console.log('Cancel');
            },
        });
    }

    //获取列表
    getList = (listQuery) => {
        Api.getLoggerList(listQuery).then(res => {
            if (res.code == 200) {
                this.setState({ data: res.data.result, total: res.data.total })
            }
        })
    }
    render() {
        return (
            <div className="table_box_bg">
                <BaseTable {...this.state} />
            </div>
        )
    }
}

export default withRouter(Logger)

